<template>
  <div class="prescription" :style="printConfig.type === 1 ? 'border-left: none;border-right: none;padding: 15px 0 0 0;': 'padding: 15px 15px 0 15px;'">
    <!-- 贴敷 -->
    <template v-if="info.parescriptOrder && info.parescriptOrder.prescriptionType == 1">
      <div>
        RP: （共 {{ getTiefuTotal(info.parescriptOrder.materialsDetail, 'prescriptNum')}} 贴
        <span v-if="styleType !== 'print'">，已核销 {{ getTiefuTotal(info.parescriptOrder.materialsDetail, 'auditNum') }} 贴</span>
        ）：
      </div>
      <div
        v-for="(stick, stickIndex) in info.parescriptOrder.materialsDetail"
        :key="stickIndex"
        class="disFlx fz-12 py-10"
        :class="{ dottedLine: stickIndex !== 0 }"
      >
        <div class="shrink0 mr-5 materialsTag">贴{{ stickIndex + 1 }}</div>
        <div>
          <div class="py-5">
            <span>药材：</span>
            <span
              v-for="(materials, materialsIndex) in stick.materials"
              :key="materials.materialsId"
            >
              <span>{{ materials.materialsName }}</span>
              <span>{{ materials.dose }}</span>
              <span>{{ materials.unitName ? materials.unitName: findUnitName(materials.unitId) }}</span>
              <span class="pr-5">{{
                materialsIndex + 1 !== stick.materials.length ? "," : ""
              }}</span>
            </span>
          </div>
          <div class="spanGird py-5">
            <span>调法：{{ stick.tcmModulate }}</span>
            <span>用法：{{ stick.tcmUsage }}</span>
          </div>
          <div class="spanGird py-5">
            <span class="mr-15">
              穴位：
              <span
                v-for="(acupoints, acupointsIndex) in stick.acupoints"
                :key="acupoints.id"
                class="mr-1"
                effect="plain"
              >
                <span>{{ acupoints.acupointName }}</span>
                <span class="pr-5">{{
                  acupointsIndex + 1 !== stick.acupoints.length ? "," : ""
                }}</span>
              </span>
            </span>
            <span v-if="stick.dailyPrescriptNum" style="margin-left: 0;">每日 {{ stick.dailyPrescriptNum }} 贴,</span>
            <span v-if="stick.days" style="margin-left: 0;">共 {{ stick.days }} 日,</span>
            <span v-if="stick.timeLength" style="margin-left: 0;">每次 {{ stick.timeLength }} 小时</span>
          </div>
        </div>
      </div>
      <div v-if="printConfig.type !== 1" style="flex: 1"></div>
      <div v-if="printConfig.type !== 1" class="py-5">
        <span>医嘱：</span>
        <span v-if="info.parescriptOrder">{{
          info.parescriptOrder.remark
        }}</span>
      </div>
      <slot></slot>
    </template>

    <template v-else-if="prescriptionInfo">
      <div>RP: （共{{ prescriptionInfo.checkItem.length || 0 }}项）：</div>
      <div class="printGrid">
        <div
          v-for="checkItem in prescriptionInfo.checkItem"
          :key="checkItem.itemId"
        >
          <div class="fw-7">{{ checkItem.itemName }}</div>
          <div class="py-5">
            {{ checkItem.specsNum }}{{ checkItem.unit || "项" }}
          </div>
        </div>
      </div>
      <div v-if="printConfig.type !== 1" style="flex: 1"></div>
      <div class="py-3">
        <span class="fw-7">{{info.orderSource === 0 ? '用法：' : '用法用量：'}}</span>
        <template v-if="info.parescriptOrder && info.parescriptOrder.regulateDosage">
          <span class="px-1">共{{info.parescriptOrder.regulateDosage.courseNum}}疗程</span>
          <span v-if="styleType !== 'print'" class="px-1">，{{ prescriptionInfo.prescriptNum }}剂</span>
          <span v-if="prescriptionInfo.takeType === 1" class="px-1">，口服</span>
          <span v-if="prescriptionInfo.takeType === 2" class="px-1">，外用</span>
          <span class="px-1">，每日{{ info.parescriptOrder.regulateDosage.usageDose }}次</span>
          <span class="px-1">，每次{{ info.parescriptOrder.regulateDosage.onceDose }}袋/格</span>。
        </template>
        <template v-else>
          <span v-if="prescriptionInfo.serviceItems == 4 && prescriptionInfo.prescriptNum" class="px-1">共{{ prescriptionInfo.prescriptNum }}剂</span>
          <span v-else class="px-1">，共 {{ prescriptionInfo.itemNum }} 项</span>
          <span v-if="prescriptionInfo.takeType === 1" class="px-1">，口服</span>
          <span v-if="prescriptionInfo.takeType === 2" class="px-1">，外用</span>
          <span v-if="prescriptionInfo.usageDose" class="px-1">，每日{{ prescriptionInfo.usageDose }}次</span>
          <span v-if="prescriptionInfo.usageDose" class="px-1">，每次{{ prescriptionInfo.onceDose || 1 }}袋/格</span>
          <span v-if="prescriptionInfo.dictLabel === '中药颗粒'">，开水冲泡，待温口服</span>。
        </template>
      </div>

      <div v-if="printConfig.type !== 1" class="py-5">
        <span class="fw-7">医嘱：</span>
        <span v-if="info.parescriptOrder">{{
          info.parescriptOrder.remark
        }}</span>
      </div>
      <slot></slot>
    </template>
  </div>
</template>

<script>
import { getSelectList } from "@/api/system/unit";

export default {
  props: {
    info: {
      type: Object,
      default: () => { }
    },
    prescriptionInfo: {
      type: Object,
      default: () => { }
    },
    printConfig: {
      type: Object,
      default: () => { }
    },
    styleType: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      unitList: []
    }
  },
  created () {
    getSelectList({ pageNum: 1, pageSize: 999 }).then(res => {
      this.unitList = res.rows;
    });
  },
  methods: {
    // 获取贴敷总数
    getTiefuTotal(list, key) {
      let total = 0;
      list.forEach(v => {
        console.log(v[key]);
        total += v[key] || 0;
      });

      return total;
    },
    findUnitName(unitId) {
      const item = this.unitList.find(v => v.unitId === unitId);
      return item ? item.unit : '项'
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
